package xiaomi;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int n,m,m3;
        Scanner scanner=new Scanner(System.in);
        n=scanner.nextInt();
        m=scanner.nextInt();
        m3=scanner.nextInt();

        int [][] op=new int[m][m3];//m行3列用来存操作数
        //输入m行3列操作数的值
        for(int i=0;i<m;++i){
            for(int j=0;j<m3;++j){
                op[i][j]=scanner.nextInt();
            }
        }
        System.out.println("he");
        System.out.println(matrixNum(n,op));
    }

    public static long matrixNum(int n,int[][] op){
        int[][] query=new int[n][n];
        long res=0L;
        int type=0,index=0,val;
        int h= op.length;
        for(int i=0;i<h;++i){
            type=op[i][0];
            index=op[i][1];
            val=op[i][2];
            if(type==0){
                for(int k=0;k<n;++k){
                    query[k][index]=val;
                }
            }else{
                for(int k=0;k<n;++k){
                    query[index][k]=val;
                }
            }
        }

        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                res+=query[i][j];
            }
        }
        return res;
    }
}


//3
//4 3
//0 0 1
//1 2 2
//0 2 3
//1 0 4